/***************************************************************************
 *   Copyright (C) 2008 by Goliash   *
 *   goliash@goliash.net   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QSettings>
#include <QApplication>

#include "preferences.h"


Preferences* Preferences::_instance = 0;


Preferences::Preferences(QObject *parent)
 : QObject(parent)
{
	reset();
	load();
}

Preferences::~Preferences()
{
	save();
}

Preferences* Preferences::instance()
{
    if (_instance == 0)
        _instance = new Preferences();

    return _instance;
}

void Preferences::deleteInstance()
{
    if (_instance)
        delete _instance;
    _instance = 0;
}

void Preferences::reset()
{
	device = "";
	
	// used filters
	filter_JPEG = true;
	filter_txt = false;
	filter_mp3 = false;
	
	// picture tab
	thumbnail = true;
	exif = true;
	thumbnail_size = 120;

	// mp3 tab
	tag_charset = "UTF-8";
}

void Preferences::save()
{
	QSettings s("Software Inc.", "DiskMuster");

	s.setValue("prefs/device", device);

	// used filters
	s.setValue("prefs/filter-JPEG", filter_JPEG);
	s.setValue("prefs/filter-txt", filter_txt);
	s.setValue("prefs/filter-mp3", filter_mp3);
	s.setValue("prefs/filter-pdf", filter_pdf);

	// picture tab
	s.setValue("picture/thumbnail", thumbnail);
	s.setValue("picture/exif", exif);
	s.setValue("picture/thumbnail-size", thumbnail_size);

	// mp3 tab
	s.setValue("mp3/tag-charset", tag_charset);
}

void Preferences::load()
{
	QSettings s("Software Inc.", "DiskMuster");
	
	device = s.value("prefs/device", "").toString();

	// used filters
	filter_JPEG = s.value("prefs/filter-JPEG", true).toBool();
	filter_txt = s.value("prefs/filter-txt", true).toBool();
	filter_mp3 = s.value("prefs/filter-mp3", true).toBool();
	filter_pdf = s.value("prefs/filter-pdf", true).toBool();

	// picture tab
	thumbnail = s.value("picture/thumbnail", true).toBool();
	exif = s.value("picture/exif", true).toBool();
	thumbnail_size = s.value("picture/thumbnail-size", 120).toInt();

	// mp3 tab
	tag_charset = s.value("mp3/tag-charset", "UTF-8").toString();
}
